﻿using System;
using System.Linq;

namespace Borg
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
    public sealed class ParamValueAttribute : Attribute
    {
        private string[] _plugs;

        public string Name { get; private set; }

        public object Value { get; private set; }

        public string Plug
        {
            get { return Plugs.Length != 0 ? Plugs[0] : null; }
            set { Plugs = new[] { value }; }
        }

        public string[] Plugs
        {
            get { return _plugs; }
            set { _plugs = value ?? new string[0]; }
        }

        public ParamValueAttribute(string name, object value, params string[] plugs)
        {
            Name = name;
            Value = value;
            Plugs = plugs;
        }

        public bool IsForPlug(string plug)
        {
            return
                Plugs == null ||
                Plugs.Length == 0 ||
                Plugs.Contains(plug);
        }
    }
}

